<?php

namespace app\admin\controller;
use app\BaseController;
use app\Request;
use app\admin\model\Nav as model_nav;


class Nav extends BaseController
{

    public function lists(){

        $list=model_nav::order('sort asc')->select();
        $status=[
            1=>'显示',
            2=>'隐藏'
        ];

        return view('',['list'=>$list,'status'=>$status]);
    }
    /***
     * 添加编辑栏目
     */
    public function editNav(Request $request){

        $id= input('id');
        if($request->isPost() && $request->isAjax()){

            $id= input('id');

            empty($id) ? $type='add':$type='edit';
            if($type=='add'){
                $result= model_nav::insertNav();
                return json($result);
            }else{

                $result= model_nav::modifyNav();
                return json($result);
            }
        }
        $info=model_nav::where(['id'=>$id])->find();

        empty($id) ? $tpl='add_nav':$tpl='edit_nav';

        return \view($tpl,['info'=>$info]);
    }


    public function NavDel(){

        $result=model_nav::del();
        return $result;
    }

}